package com.wyh.controller;


import com.wyh.common.annotation.Log;
import com.wyh.common.annotation.RateLimiter;
import com.wyh.common.enums.BusinessType;
import com.wyh.common.response.PageInfo;
import com.wyh.common.result.R;
import com.wyh.common.util.ExcelUtils;
import com.wyh.entity.AdminAttention;
import com.wyh.request.AdminAttentionRequest;
import com.wyh.service.IAdminAttentionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

/**
 * 关注功能控制层
 *
 * @author WangYuHang
 * @date 2024-03-03
 */
@Slf4j
@AllArgsConstructor
@RestController
@Api(value = "关注功能接口管理",tags = "关注功能接口管理")
@RequestMapping("/admin/adminAttention" )
public class AdminAttentionController {

    private final IAdminAttentionService iAdminAttentionService;

    /**
     * 分页查询关注功能列表
     */
    @ApiOperation(value = "分页查询关注功能列表")
    @PostMapping("/pageList")
    public R<PageInfo<AdminAttention>> pageList(@RequestBody AdminAttentionRequest adminAttentionRequest) {
        return R.success(iAdminAttentionService.pageList(adminAttentionRequest));
    }

    /**
     * 获取关注功能详细信息
     */
    @ApiOperation(value = "获取关注功能详细信息")
    @GetMapping(value = "/query/{id}")
    public R<AdminAttention> detail(@PathVariable("id") Integer id) {
        return R.success(iAdminAttentionService.getById(id));
    }

    /**
     * 保存关注功能
     */
    @Log(title = "新增关注功能", businessType = BusinessType.INSERT)
    @RateLimiter
    @ApiOperation(value = "新增关注功能")
    @PostMapping("/save")
    public R<Void> add(@RequestBody AdminAttentionRequest adminAttentionRequest) {
        iAdminAttentionService.add(adminAttentionRequest);
        return R.success();
    }

    /**
     * 修改关注功能
     */
    @Log(title = "修改关注功能", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改关注功能")
    @PostMapping("/update")
    public R<Void> edit(@RequestBody AdminAttentionRequest adminAttentionRequest) {
        iAdminAttentionService.update(adminAttentionRequest);
        return R.success();
    }

    /**
     * 删除关注功能
     */
    @Log(title = "删除关注功能", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除关注功能")
    @PostMapping("/delete/{ids}")
    public R<Void> remove(@PathVariable Integer[] ids) {
        iAdminAttentionService.deleteBatch(Arrays.asList(ids));
        return R.success();
    }

    /**
    * 导出关注功能
    *
    * @param response response
    * @throws IOException IOException
    */
    @PostMapping(value = "/export")
    public void exportExcel(HttpServletResponse response,@RequestBody AdminAttentionRequest adminAttentionRequest) throws IOException {
        List<AdminAttention> list = iAdminAttentionService.list(adminAttentionRequest);
        ExcelUtils.exportExcel(list, AdminAttention.class, "关注功能信息", response);
    }
}
